<?php 
$container_tr=join("&nbsp;", $form->_button_container["TR"]);
$container_bl=join("&nbsp;", $form->_button_container["BL"]);
$container_br=join("&nbsp;", $form->_button_container["BR"]);
$cliente=$form->cliente->value;
$id=$this->datasis->dameval("SELECT id FROM scli WHERE cliente='$cliente'");

if ($form->_status=='delete' || $form->_action=='delete' || $form->_status=='unknow_record'):
	$meco = $form->output;
	$meco = str_replace('class="tablerow"','class="tablerow" style="font-size:20px; align:center;" ',$meco);
	echo $meco."</td><td align='center'>".img("images/borrar.jpg");
else:
?>
<?php echo $form_scripts?>
<?php echo $form_begin?>
<?php if(isset($form->error_string))echo '<div class="alert">'.$form->error_string.'</div>'; ?>
<table border='0' width='95%' style='background: #EEEEEE'>
	<tr>
		<td align='center' valign='middle' width='38'>
			<a href='<?php echo base_url()."reportes/index/scli" ?>'>
			<?php
				$propiedad = array('src' => 'images/reportes.gif', 'alt' => 'Reportes', 'title' => 'Reportes','border'=>'0','height'=>'20');
				echo img($propiedad);
			?>
			</a>		</td>
		<td align='center' valign='middle' width='18'>
			<?php
				$sta_cod=$form->stacod->output;
				IF(($sta_cod=='FACTURADO')||($sta_cod=='PRESUPUESTADOS')){
					$status='A';
				}else{
					$status='I';
				}
				//echo 'aqui'.$sta_cod.$status; 
				$propiedad = array('src' => "images/$status.png",'border'=>'0','height'=>'20');
				echo img($propiedad);
			?>		</td>
		<td align='center' valign='middle' width='34'></td>
		<td width="335" align='center' valign='middle'>
			<?php  //if ($form->tipo->value=='0') echo "<div style='font-size:14px;font-weight:bold;color: #B40404'>***DESACTIVADO***</div>"; ?>&nbsp;		</td>
		<td width="589" align='right'><?php echo $container_tr; ?></td>
	</tr>
</table>
<fieldset style='border: 2px outset #9AC8DA;background: #FFFFFF;'>
<legend class="titulofieldset" style='color: #2E4B77;'>Identificaci&oacute;n</legend>
<table border='0' width="100%">
	<tr>
		<td>
			<table border='0' width="100%">
				<tr>
					<td  width="20%"class="littletableheaderc"><?=$form->cliente->label  ?></td>
					<td  width="10%" class="littletablerow" ><?=$form->cliente->output ?></td>
					<td  width="5%" class="littletableheaderc"><?=$form->rifci->label ?></td>
					<td  class="littletablerow"><?php echo $form->rifci->output ?>
					<?php if($form->_status=='show'){ ?>
					<a href="#" onclick="window.open('<?php echo trim($this->datasis->traevalor("CONSULRIF"))."?p_rif=".trim($form->rifci->value);?>','CONSULRIF','height=1000,width=1100')" title="DIAN" style='color:red;font-size:9px;border:none;'>DIAN</a>
					<?php } ?></td>
				</tr>	
				<tr>
					<td class="littletableheaderc"><?=$form->nombre->label ?></td>
					<td colspan='3' class="littletablerow"><?=$form->nombre->output?></td>
				</tr>
				<tr>
					<td class="littletableheaderc"><?=$form->contacto->label ?></td>
					<td colspan='3' class="littletablerow"><?=$form->contacto->output?></td>
				</tr>
				<tr>
					<td rowspan="2" class="littletableheaderc"><?=$form->dire11->label ?></td>
					<td colspan='3' class="littletablerow"><?=$form->dire11->output ?></td>
				</tr>
				<tr>
				  <td colspan='3' class="littletablerow"><?=$form->dire12->output ?></td>
			  </tr>
				<tr>
					<td class="littletableheaderc"><?=$form->telefono->label ?></td>
					<td colspan='3' class="littletablerow"><?=$form->telefono->output?></td>
				</tr>
				<tr>
					<td class="littletableheaderc"><?=$form->tip_cod->label ?></td>
					<td colspan='3' class="littletablerow" ><?=$form->tip_cod->output?></td>
				</tr>
				<tr>
					<td class="littletableheaderc"><?=$form->fuecod->label ?></td>
					<td colspan='3' class="littletablerow" ><?=$form->fuecod->output?></td>
				</tr>
				<tr>
					<td class="littletableheaderc"><?=$form->stacod->label ?></td>
					<td colspan='3' class="littletablerow" ><?=$form->stacod->output?></td>
				</tr>
				<tr>
					<td class="littletableheaderc"><?=$form->grupo->label ?></td>
					<td colspan='3' class="littletablerow"><?=$form->grupo->output?></td>
				</tr>
				<tr>
					<td class="littletableheaderc"><?=$form->cat_cod->label ?></td>
					<td colspan='3' class="littletablerow"><?=$form->cat_cod->output?></td>
				</tr>
			</table>
		</td>
		<td valign='top' width='25%'>
				<fieldset style='border: 1px dotted #297FA2;background: #FFFBE9;'>
					<legend class="titulofieldset" style='color: #2E4B77;'>Credito</legend>
					<table width= '100%' >
						<tr>
							<td class="littletableheaderc"><?=$form->formap->label  ?></td>
							<td class="littletablerow"><?=$form->formap->output ?></td>
						</tr>
						<tr> <? $limite=$form->limite->output;?>
							<td class="littletableheaderc"><?=$form->limite->label  ?></td>
							<td class="littletablerow"><?= $form->limite->output ?></td>
						</tr>
						<?php if($form->_status=='show'){ ?>
						<? $saldop=$this->datasis->dameval("SELECT sum(monto)-sum(abonos)as saldo from smov where cod_cli='$cliente' and tipo_doc='FC' AND abonos<monto");?>
						<tr>
						  <td class="littletableheaderc">Saldo Pendiente </td>
							  <td class="littletablerow"><strong><?php echo nformat($saldop) ?></strong></td>
					  </tr>	
					  <? } ?>		
					</table>
				</fieldset>
		</td>
	</tr>
</table>
</fieldset>
<div id="maintabcontainer">
	<ul>
		<li><a href="#tab1">Historico</a></li>
		<li><a href="#tab9">Contactos</a></li>
		<li><a href="#tab2">Ubicaci&oacute;n</a></li>
		<li><a href="#tab4">Facturaci&oacute;n</a></li>
		<li><a href="#tab8">Presupuestos</a></li>
		<li><a href="#tab5">Representantes</a></li>
		<li><a href="#tab6">Vendedor</a></li>
		<li><a href="#tab3">Adicional</a></li>
		<li><a href="#tab10">Movimientos de Usuarios</a></li>
	</ul>
<? $mSQL=$this->db->query("SELECT * from logusu WHERE comenta like '%$cliente%' and modulo='SCLI' ORDER BY fecha DESC limit 10");?>
<div id="tab10" style='background:#EFEFFF'>
 <table width='70%'>
	<tr>
		<td valign='top'>
			<fieldset style='border: 1px outset #B45F04;background: #FFFFFF;'>
			<legend class="titulofieldset" >Lista de las 10 Ultimas  Actividades Realizadas al Cliente</legend>
			<table border='0' width="100%" >
				<tr bgcolor="#A5C1A5">
					<td class='littletableheaderc' width="15%" align="center">Fecha</td>
					<td class="littletableheaderc" width="15%" align="center">Hora</td>
				    <td class="littletableheaderc" width="15%" align="center">Usuario</td>
				    <td class="littletableheaderc" width="55%" align="left">Actividad</td>
				</tr>
				<? foreach($mSQL->result() as $items){?>
				<tr>
					<td class='littletablerow' align="center"><?= dbdate_to_human($items->fecha) ?></td>
					<td class="littletablerow" align="center"><?= $items->hora   ?></td>
				    <td class="littletablerow" align="center"><?= $items->usuario?></td>
				    <td class="littletablerow" align="left"><?= $items->comenta?></td>
				</tr>
				<? } ?>
			</table>
			 </legend>
	        </fieldset>
		</td>
		</tr>
	</table>
</div>
<div id="tab6">
	<fieldset style='border: 2px outset #BAC3CF;background:#EFEFEF;'>
		<table >
			<tr>
				<td class="littletableheaderc"><?=$form->vendedor->label  ?></td>
				<td class="littletablerow"><?=$form->vendedor->output ?></td>
				<td class="littletableheaderc">Comision %</td>
				<td class="littletablerow"><?=$form->porvend->output ?></td>
			</tr>				
			<tr>
				<td class="littletableheaderc"><?=$form->cobrador->label  ?></td>
				<td class="littletablerow"><?=$form->cobrador->output ?></td>
				<td class="littletableheaderc">Comision %</td>
				<td class="littletablerow"><?=$form->porcobr->output ?></td>
			</tr>				
		</table>
	</fieldset>
</div>
<div id="tab2"  style='background:#EFEFEF'>
				<table border='0' width='90%' >
					<tr>
					  <td colspan="4" class="littletableheaderc">Ubicaci&oacute;n Geogr&aacute;fica </td>
				  </tr>
					<tr>
					  <td colspan="4" class="littletablerow"><?php echo $form->itscli->output ?>
					  </td>
				  </tr>
				</table>
	<br/>
</div>
<div id="tab5">
	<fieldset style='border: 2px outset #BAC3CF;background: #EFEFEF;'>
		<table width= '100%' >
			<tr>
				<td  width="20%"class="littletableheaderc">Representante Legal</td>
				<td class="littletablerow"><?=$form->repre->output ?></td>
			</tr>
			<tr>
				<td class="littletableheaderc">DNI</td>
				<td class="littletablerow"><?=$form->cirepre->output ?></td>
		</tr>
			<tr>
			  <td class="littletableheaderc"><?=$form->fiador->label  ?></td>
			  <td class="littletablerow"><?=$form->fiador->output  ?></td>
		  </tr>
		  <tr>
			  <td class="littletableheaderc"><?=$form->dnif->label  ?></td>
			  <td class="littletablerow"><?=$form->dnif->output  ?></td>
		  </tr>
			<tr>
			  <td class="littletableheaderc"><?=$form->domiciliof->label  ?></td>
			  <td class="littletablerow"><?=$form->domiciliof->output  ?></td>
		  </tr>	
		  	<tr>
			  <td class="littletableheaderc"><?=$form->telefonof->label  ?></td>
			  <td class="littletablerow"><?=$form->telefonof->output  ?></td>
		  </tr>						
		</table>
	</fieldset>
</div>
<div id="tab3">
	<fieldset style='border: 2px outset #BAC3CF;background: #EFEFEF;'>
		<table width= '80%' >			
			<tr>
				<td  width= '15%' class="littletableheaderc"><?=$form->observa->label  ?></td>
				<td class="littletablerow"><?=$form->observa->output ?></td>
			</tr>				
		</table>
	</fieldset>
</div>
<div id="tab4">
	<fieldset style='border: 2px outset #BAC3CF;background: #EFEFEF;'>
		<?php if($form->_status=='show'){ ?>
						<?php
					$mSQL="SELECT a.moneda,b.id,a.numero, (a.monto-a.abonos) as resta,a.fecha, a.monto, a.impuesto, a.abonos 
					FROM smov as a
					JOIN sfac as b ON a.idfactura=b.id
 					WHERE a.cod_cli='$cliente'";
					//echo $mSQL;
					$query = $this->db->query($mSQL);
					if($query->num_rows() == 0) {
						echo "No tiene ventas registradas";
					} else {
						$result= $query->result(); ?>
						<table width="60%">
							<tr>
								<td class='littletableheaderc'  width='6%' >&nbsp;</td>
								<td class='littletableheaderc'  width='6%' >Fecha</td>
								<td class='littletableheaderc' align='center'  width='12%' >N&uacute;mero</td>
								<td class='littletableheaderc' align='center'  width='12%' >Moneda</td>
								<td  class='littletableheaderc' align='right' width='12%'>Total</td>
								<td align='right'  class='littletableheaderc' width='12%'>Abonos</td>
							    <td align='right'  class='littletableheaderc' width='6%'>Resta</td>
							    <td align='right'  class='littletableheaderc' width='6%'>&nbsp;</td>
							</tr>
							<? $ttotalg=0; $tabonos=0; $tresta=0; $i=0; foreach ($result AS $items){$i++;?>
							<? $ttotalg+=$items->monto ?>
							<? $tabonos+=$items->abonos ?>
							<? $tresta+=$items->resta ?>
							<? $numero=$items->numero ?>
							<? $idfactura=$items->id ?>
							<tr>
								<td class='littletablerow'>
		                          <div align="center"><a href="#" onclick="window.open('<?php echo base_url()."formatos/ver/FACTURA/$id" ?>','Ver Factura','height=600,width=1000,left=20,top=300')">
	                              <img src='<?php echo base_url() ?>images/pdf_logo.gif'></a></div></td>
								<td class='littletablerow'><?=dbdate_to_human($items->fecha) ?></td>
								<td class='littletablerow' align='center' >
								<a href="<?php echo base_url() ?>ventas/sfac/dataedit/show/<?=$idfactura ?>"><?=$items->numero ?></td>
								<td class='littletablerow' align='center'><?= $items->moneda ?></td>
								<td class='littletablerow' align='right'><?=nformat($items->monto) ?></td>
								<td align='right' class='littletablerow'><?=nformat($items->abonos) ?></td>
							    <td align='right' class='littletablerow'><?=nformat($items->resta) ?></td>
							</tr>
							<? }?>
    </table>
					<? }?>		
		<?php } else {
		echo "<center><h1>Informaci&oacute;n no Disponible en este Momento </h1><center>";
		}; ?>
	</fieldset>
</div>
<div id="tab8">
	<fieldset style='border: 2px outset #BAC3CF;background: #EFEFEF;'>
		<?php if($form->_status=='show'){ ?>
						<?php
					$mSQL="SELECT moneda,status,fecha,vd,numero,totals,iva,totalg,id FROM spre WHERE cod_cli='$cliente'
					ORDER BY fecha DESC LIMIT 10";
					//echo $mSQL;
					$query = $this->db->query($mSQL);
				
					if($query->num_rows() == 0) {
						echo "No tiene presupuestos registrados";
					} else {
						$result= $query->result(); ?>
						<table width="60%">
							<tr>
								<td  colspan="3" class='littletableheaderc' >&nbsp;</td>
								<td  class='littletableheaderc' >Fecha</td>
								<td  class='littletableheaderc' align='center'>N&uacute;mero</td>
								<td  class='littletableheaderc' align='center'>Moneda</td>
								<td  class='littletableheaderc' align='right'>Sub-Total</td>
								<td  class='littletableheaderc' align='right'><? echo $tiva=$this->datasis->traevalor('TIVA'); ?></td>
								<td  class='littletableheaderc' align='right'>Total</td>
								<td  class='littletableheaderc' align='center'>Vendedor</td>
							</tr>
							<? $ttotalg=0; $ttotals=0;  $i=0; foreach ($result AS $items){$i++;?>
							<? $ttotals+=$items->totals ?>
							<? $ttotalg+=$items->totalg ?>
							<? $numero=$items->numero ?>
							<? $vd=$items->vd ?>
							<? $icono=$items->status ?>
						    <? $vendedor=$this->datasis->dameval("SELECT nombre FROM vend WHERE vendedor='$vd'"); ?>
							<tr>
								<td class='littletablerow'><a href="#" onclick="window.open('<?php echo base_url() ?>formatos/verhtml/PRESUP/<?php echo $numero ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" >
		<img src='<?php echo base_url() ?>images/html_icon.gif'></a></td>
								<td class='littletablerow'><a href="#" onclick="window.open('<?php echo base_url() ?>formatos/ver/PRESUP/<?php echo $numero ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" >
		<img src='<?php echo base_url() ?>images/pdf_logo.gif'></a></td>
								<td class='littletablerow'><img src="<?php echo base_url() ?>images/<? echo $icono ?>.gif" height="12"></td>
								<td class='littletablerow'><?=dbdate_to_human($items->fecha) ?></td>
								<td class='littletablerow' align='center' >
								<a href="<?php echo base_url() ?>/ventas/spre/dataedit/show/<?=$items->id ?>"><?=$items->numero ?></a></td>
								<td class='littletablerow' align='center'><?= $items->moneda ?></td>
								<td class='littletablerow' align='right'><?=nformat($items->totals) ?></td>
								<td class='littletablerow' align='right'><?=nformat($items->iva) ?></td>
								<td class='littletablerow' align='right'><?=nformat($items->totalg) ?></td> 		        
								<td  class='littletablerow' align='center'><?= $vendedor ?></td>
							</tr>
							<? }?>
    </table>
					<? }?>		
		<?php } else {
		echo "<center><h1>Informaci&oacute;n no Disponible en este Momento </h1><center>";
		}; ?>
	</fieldset>
</div>
<div id="tab1">
	<fieldset style='border: 2px outset #BAC3CF;background:#EFEFEF;'>
		<table width="95%"  border="0">
				<tr>
					<td class='littletableheaderc' >Lista de las &uacute;ltimas diez actividades</td>
				</tr>
				<tr>
					<td ><?php echo $form->ithistory->output ?></td>
				</tr>
		</table>
	</fieldset>
</div>
<div id="tab9">
	<table style='width: 100%;border: 1px dotted #297FA2;'>
	  <tr>
		<td colspan='2' class="littletableheaderc">Lista de Contactos</td>
	  </tr>
	  <tr>
			<td class="littletablerow"    ><?=$form->itubica->output ?></td>
	  </tr>
	</table>
</div>
<?php echo $container_bl.$container_br; ?>
<?php echo $form_end?>
<?php endif; ?>
